<?php

class Control_MessagesController extends Zend_Controller_Action {

    public function init() {
        $this->_helper->layout->setLayout('admin');
        $this->yesButton = 'Yes'; //напис на кнопці Так під час видалення
        $this->noButton = 'No'; //напис на кнопці Ні під час видалення
        $this->dbTable = new Control_Model_Table_Message();
        $this->view->controller = $this->getRequest()->getControllerName();
        $this->view->action = $this->getRequest()->getActionName();
    }

    public function indexAction() {
        //        $this->_helper->redirector('edit');
        $this->view->allMessages = $this->dbTable->getAllMessages();
        $id = (int) $this->_getParam('id', 0);
        $del = (int) $this->_getParam('del', 0);
        $this->view->getId = $id;
        if (($id > 0) && ($del == '0')) {
            $this->view->dataId = $this->dbTable->getDataID($id);
        } elseif (($id > 0) && ($del == '1')) {
            $this->dbTable->deleteData($id);
            $this->_helper->redirector('index', 'messages');
        }
    }

    public function countAction() {
        $this->view->messagesCount = count($this->dbTable->getAllUnreadedCount());
        //        Zend_Debug::dump(count($this->dbTable->getAllUnreaded()));exit();
    }

    public function popAction() {
        $this->view->messages = $this->dbTable->getAllUnreaded();
    }

    public function allReadedAction() {
        $this->dbTable->allReaded();
        $this->_helper->redirector('index', 'messages');
    }

    public function exitallReadedAction() {
        // action body
    }

}

